import React, { Component } from 'react'
import './Footer.css'
export default class Footer extends Component {
    handleClearAllDone=()=>{
        this.props.clearAllDone()
    }
    handleCheckAll=(event)=>{
        this.props.checkAllTodo(event.target.checked)
    }
    render() {
        const {todos}=this.props
        //reduce pre之前的参数  勾选的个数
        //const doneCount=todos.reduce((pre,todo)=>{return pre + (todo.done ? 1 : 0)},0)
        const doneCount=todos.reduce((pre,todo)=> pre + (todo.done ? 1 : 0),0)
        //总数
        const total=todos.length
        return (
            <div className='todo-footer'>
                <label>
                    <input type='checkbox' onChange={this.handleCheckAll} checked={doneCount === total && total !== 0 ? true : false}/>
                </label>
                <span>
                    <span>已完成{doneCount}/全部{total}</span>
                </span>
                <button className='btn btn-danger' onClick={this.handleClearAllDone}>清除已完成任务</button>
            </div>
        )
    }
}
